import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:keep_accounts/routes.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'db/object_box.dart';
import 'home_page.dart';

late ObjectBox objectBox;
// late Admin admin;
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  objectBox = await ObjectBox.create();

  // flog("--------------${Admin.isAvailable()}");
  // if (Admin.isAvailable()) {
  //   admin = Admin(objectBox.store);
  // }
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      headerBuilder: () =>
      const MaterialClassicHeader(), // 配置默认头部指示器,假如你每个页面的头部指示器都一样的话,你需要设置这个
      footerBuilder: () => const ClassicFooter(
        loadingText: "加载中……",
        noDataText: "没有更多数据了!",
        idleText: "上拉加载",
      ), // 配置默认底部指示器
      headerTriggerDistance: 80.0, // 头部触发刷新的越界距离
      springDescription: const SpringDescription(
          stiffness: 170,
          damping: 16,
          mass: 1.9), // 自定义回弹动画,三个属性值意义请查询flutter api
      maxOverScrollExtent: 100, //头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
      maxUnderScrollExtent: 0, // 底部最大可以拖动的范围
      enableScrollWhenRefreshCompleted:
      true, //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
      enableLoadingWhenFailed: true, //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
      hideFooterWhenNotFull: false, // Viewport不满一屏时,禁用上拉加载更多功能
      enableBallisticLoad: true, // 可以通过惯性滑动触发加载更多
      child: GetMaterialApp(
        title: '每天记账',
        debugShowCheckedModeBanner: false,
        getPages: Routes.getPages,
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
        ),
        home: const HomePage(title: '记账'),
        localizationsDelegates: GlobalMaterialLocalizations.delegates,
        supportedLocales: const [
          Locale('zh', 'CH'),
          Locale('en', 'US'),
        ],
        locale: const Locale('zh'),
      ),
    );
  }
}